/*
 * Copyright 2019-2020 by Nedim Sabic Sabic
 * https://www.fibratus.io
 * All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package elasticsearch

import (
	"github.com/rabbitstack/fibratus/pkg/event"
	"github.com/stretchr/testify/assert"
	"testing"
	"time"
)

func TestProduceIndexName(t *testing.T) {
	i := index{config: Config{IndexName: "fibratus-%Y-%m"}}

	ts, _ := time.Parse(time.RFC3339, "2011-05-03T15:04:05.323Z")

	indexName := i.getName(&event.Event{Timestamp: ts})
	assert.Equal(t, "fibratus-2011-05", indexName)

	i = index{config: Config{IndexName: "fibratus-%y-%d"}}

	indexName = i.getName(&event.Event{Timestamp: ts})
	assert.Equal(t, "fibratus-11-03", indexName)

	i = index{config: Config{IndexName: "fibratus-%d-%H"}}

	indexName = i.getName(&event.Event{Timestamp: ts})
	assert.Equal(t, "fibratus-03-15", indexName)

	i = index{config: Config{IndexName: "fibratus-events"}}

	indexName = i.getName(&event.Event{Timestamp: ts})
	assert.Equal(t, "fibratus-events", indexName)
}
